import { http } from "@/utils/http";
import { PageResponse } from "@/api/model/baseModel";
import { DictBase, DictModel } from "@/api/model/dictModel";

enum Api {
  DictList = "/dict/list",
  SaveDict = "/dict/save",
  DIctChildrenByCode = "/dict/childrenByCode",
  DIctChildrenById = "/dict/childrenById",
}

export function dictList(params: DictModel) {
  return http.get<PageResponse<DictModel>>({
    url: Api.DictList,
    params,
  });
}

export function saveDict(dict: DictModel) {
  return http.post<DictModel>({
    url: Api.SaveDict,
    params: dict,
  });
}

export function translateDict(code: string) {
  return http.get<string>({
    url: `/dict/${code}/translate`,
  });
}

export function checkCode(code: string, id?: string) {
  return http.get<Boolean>({
    url: `/dict/check/${code}`,
    params: { id },
  });
}

export function childrenByCode(code: string) {
  return http.get<DictBase[]>({
    url: Api.DIctChildrenByCode,
    params: { code },
  });
}
export function childrenById(parentId: string) {
  return http.get<DictModel[]>({
    url: Api.DIctChildrenById,
    params: { parentId },
  });
}

export function changeState(id: string, state: boolean) {
  return http.post<Boolean>({
    url: `/dict/state/${id}/${state}`,
  });
}

export function deleteDict(id: string) {
  return http.post<string>({
    url: `/dict/deleteDict/${id}`,
  });
}
